import os
import json


# file_dir = r"I:\0_Deep_Learning\磁瓦\磁瓦数据集_1_3_正面--sss\1工位\dataset"
file_dir = r"I:\0_Deep_Learning\磁瓦\磁瓦数据集_1_3_正面--sss\1工位\dataset_split\val"

qx_class = []
qx_num = {}

# write_file_name = r'train.txt'
# write_file = open(write_file_name, "w", encoding='utf-8')

i = 0
# names = []
FileNames = os.listdir(file_dir)

for fp in FileNames:
    if fp.endswith('.json'):
        root = open(os.path.join(file_dir, fp), 'rb')
        data = json.load(root)
        shapes = data["shapes"]

        # 检查空标注
        # if len(shapes) == 0:
        #     i += 1
        #     print(fp)
        #     write_file.write(fp + '\n')
            
        for s in shapes:
            label = s['label']

            # if label == "duocengmian":
            #     print(fp)
            #     if fp not in qx_class:
            #         qx_class.append(fp)
            #         write_file.write(fp + '\n')
                
            if label not in qx_class:
                # print(label, ' : ', fp)
                qx_class.append(label)
                qx_num[label] = 1
            else:
                qx_num[label] += 1


print('缺陷类别有：', qx_class)
print('各缺陷个数为：', qx_num)
print("共有：", i, " 个")